<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }

        .box input {
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }

        .box img {
            position: absolute;
            top: 2px;
            right: 2px;
            width: 24px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <img src="images/close.png" alt="" id="eye">
        </label>
        <input type="password" name="" id="pwd">
    </div>
    <script>
        /* 
            点击图片，显示表单的密码，再次点击，隐藏密码
        */
        var img = document.querySelector('img');
        var input = document.querySelector('input');
        // 疫情扫码，绿码同行，红码禁止
        // 默认是 text 状态
        var flag = true; // 记录当前的状态，不同的状态，进行不同的操作
        img.onclick = function () {

            if (flag) {
                input.type = 'password';
                img.src = 'images/close.png';
                flag = !flag;
            } else {
                input.type = 'text';
                img.src = 'images/open.png';
                flag = !flag;
            }
        }


    </script>
</body>
</html>